#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
struct mtx {
	int n, m; vector<vector<long long>> a;
	void resize(int N, int M) {n = N; m = M; a = vector<vector<long long>>(N, vector<long long>(M, -0x3f3f3f3f3f3f3f3f));}
	mtx() {resize(0, 0);} mtx(int N, int M) {resize(N, M);}
};
mtx operator + (const mtx &x, const mtx &y) {
	mtx res(x.n, y.m); for (int i = 0; i < x.n; i++) for (int j = 0; j < y.m; j++) {
		for (int k = 0; k < x.m; k++) res.a[i][j] = max(res.a[i][j], x.a[i][k] + y.a[k][j]);
	} return res;
}
int c[MAXN], v[MAXN][6]; int m;
mtx getmtx(int x) {
	mtx res(m + 1, m + 1);
	for (int i = 1; i <= m; i++) res.a[i][i] = v[x][i];
	res.a[0][0] = res.a[0][c[x]] = res.a[c[x]][0] = v[x][c[x]];
	return res;
}
namespace sgt {
	mtx val[MAXN << 2]; void pushup(int rt) {val[rt] = val[rt << 1] + val[rt << 1 | 1];}
	void build(int rt, int l, int r) {
		if (l == r) return val[rt] = getmtx(l), void(); int mid = (l + r) >> 1;
		build(rt << 1, l, mid); build(rt << 1 | 1, mid + 1, r); pushup(rt);
	}
	void modify(int rt, int l, int r, int x) {
		if (l == r) return val[rt] = getmtx(l), void(); int mid = (l + r) >> 1;
		x <= mid ? modify(rt << 1, l, mid, x) : modify(rt << 1 | 1, mid + 1, r, x); pushup(rt);
	}
	void query(int rt, int l, int r, int x, int y, mtx &res) {
		if (x <= l && r <= y) return res = res + val[rt], void(); int mid = (l + r) >> 1;
		if (x <= mid) query(rt << 1, l, mid, x, y, res); if (y > mid) query(rt << 1 | 1, mid + 1, r, x, y, res);
	}
}
int main() {
	freopen("paint.in", "r", stdin);
	freopen("paint.out", "w", stdout);
	int n, q; scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &v[i][j]);
	sgt::build(1, 1, n); long long lastans; printf("%lld\n", lastans = sgt::val[1].a[0][0]);
	while (q--) {
		int op; long long x, y; scanf("%d %lld %lld", &op, &x, &y);
		x ^= lastans; y ^= lastans;
		if (op == 1) c[x] = y, sgt::modify(1, 1, n, x);
		if (op == 2) {mtx res(1, m + 1); res.a[0][0] = 0; sgt::query(1, 1, n, x, y, res); printf("%lld\n", lastans = res.a[0][0]);}
	}
}
